using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;
//using ShivamEMR.Web.Areas.Company.Models;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class DesignationController : Controller
    {
		private readonly IDesignationRepository designationRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DesignationController() 
        {
            designationRepository = Registry.RepositoryFactory.GetDesignationRepository();
        }

        public DesignationController(IDesignationRepository designationRepository)
        {
			this.designationRepository = designationRepository;
        }

        //
        // GET: /Designation/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
           // return View(designationRepository.AllIncluding(designation => designation.Employees));
            return View(designationRepository.All);
        }

        //
        // GET: /Designation/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(designationRepository.Find(id));
        }

        //
        // GET: /Designation/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Designation/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(Designation designation)
        {
            if (ModelState.IsValid) {
                designationRepository.Create(designation);
                designationRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /Designation/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
             return View(designationRepository.Find(id));
        }

        //
        // POST: /Designation/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(Designation designation)
        {
            if (ModelState.IsValid) {
                designationRepository.Update(designation);
                designationRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /Designation/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(designationRepository.Find(id));
        }

        //
        // POST: /Designation/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var desig = designationRepository.Find(id);
            designationRepository.Delete(desig);
            designationRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

